package cn.piesat.scanning.service.impl;

import cn.piesat.scanning.business.dq1043.flow.AlgorithmParamProjection;
import cn.piesat.scanning.dao.FlowDynamicParameterDAO;
import cn.piesat.scanning.dao.FlowFixedParameterDAO;
import cn.piesat.scanning.service.FlowAlgorithmParamsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author xhl
 */
@Service
public class FlowAlgorithmParamsServiceImpl implements FlowAlgorithmParamsService {

    @Autowired
    private FlowDynamicParameterDAO dynamicParameterDAO;
    @Autowired
    private FlowFixedParameterDAO fixedParameterDAO;


    @Override
    public Map<String, Object> findDynamicParams(String flowId, String algorithmId) {
        List<AlgorithmParamProjection> list = dynamicParameterDAO.findByFlowIdAndAlgorithmId(flowId, algorithmId);
        return list.stream()
                .collect(Collectors.toMap(AlgorithmParamProjection::getParameterKey,
                        AlgorithmParamProjection::getParameterValue, (k1,k2) -> k2));
    }

    @Override
    public Map<String, Object> findFixedParams(String flowId, String algorithmId) {
        List<AlgorithmParamProjection> list = fixedParameterDAO.findByFlowIdAndAlgorithmId(flowId, algorithmId);
        return list.stream()
                .collect(Collectors.toMap(AlgorithmParamProjection::getParameterKey,
                        AlgorithmParamProjection::getParameterValue, (k1,k2) -> k2));
    }
}
